#include "BuildGrass.h"

void cGrassBuilder::OnInit(string GrassMap,DWORD dwNum)
{
	SetTexture(L"");
	SetShader(L"");
	ifstream fin;
	fin.open(GrassMap,fstream::in);
	float x,y,z;
	vector<D3DXVECTOR3> vecGrassPos;
	while(fin>>x>>y>>z){
		vecGrassPos.push_back(D3DXVECTOR3(x,y,z));
	}
	fin.close();
	cGrass* pGrass = new cGrass;
	pGrass->OnInit("grass","grass");
	pGrass->SetGrassGrid(dwNum,vecGrassPos,10.0f);
	vecGrasses.push_back(pGrass);
}
void cGrassBuilder::Update(float dt)
{
	for(int i = 0;i!=vecGrasses.size();++i)
	{
		vecGrasses[i]->Update(dt);
	}
}

void cGrassBuilder::Render()
{
	for(int i = 0;i!=vecGrasses.size();++i)
	{
		vecGrasses[i]->Render();
	}
}

void cGrassBuilder::Release()
{
	auto itr = vecGrasses.begin();
	while(itr!=vecGrasses.end())
	{
		delete *itr;
		*itr = NULL;
		++itr;
	}
	
}
void cGrassBuilder::SetTexture(WCHAR* path)
{
	cTextureMgr* pTextureMgr = GetTextureMgr();
	pTextureMgr->PushTex(L"../../files/textures/grass/grassBlade3.png","grass");
	pTextureMgr->PushTex(L"../../files/textures/grass/grassBlade5_Alpha.dds","grass_Alpha");
}
void cGrassBuilder::SetShader(WCHAR* path)
{
	cShaderMgr* pShaderMgr = GetShaderMgr();
	pShaderMgr->PushShader(L"../../files/fxFiles/grass.fx","grass");
}